using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Enum;

namespace SProject.Paramter
{
	[Serializable]
	public class MeltingOptionItem : BasicOptionItem
	{
		private double _MinTemperature = 60.0;

		private double _MaxTemperature = 90.0;

		private double _NoiseThreshold;

		private double _PeekWidthThreshold;

		private double _PeekHightThreshold = 10.0;

		private EPeekType _PeekType;

		private double _MeltGain = 1.0;

		public double MinTemperature
		{
			get
			{
				return _MinTemperature;
			}
			set
			{
				if (_MinTemperature != value)
				{
					_MinTemperature = value;
					OnPropertyChanged("MinTemperature");
				}
			}
		}

		public double MaxTemperature
		{
			get
			{
				return _MaxTemperature;
			}
			set
			{
				if (_MaxTemperature != value)
				{
					_MaxTemperature = value;
					OnPropertyChanged("MaxTemperature");
				}
			}
		}

		public double NoiseThreshold
		{
			get
			{
				return _NoiseThreshold;
			}
			set
			{
				if (_NoiseThreshold != value)
				{
					_NoiseThreshold = value;
					OnPropertyChanged("NoiseThreshold");
				}
			}
		}

		public double PeekWidthThreshold
		{
			get
			{
				return _PeekWidthThreshold;
			}
			set
			{
				if (_PeekWidthThreshold != value)
				{
					_PeekWidthThreshold = value;
					OnPropertyChanged("PeekWidthThreshold");
				}
			}
		}

		public double PeekHightThreshold
		{
			get
			{
				return _PeekHightThreshold;
			}
			set
			{
				if (_PeekHightThreshold != value)
				{
					_PeekHightThreshold = value;
					OnPropertyChanged("PeekHightThreshold");
				}
			}
		}

		public EPeekType PeekType
		{
			get
			{
				return _PeekType;
			}
			set
			{
				if (_PeekType != value)
				{
					_PeekType = value;
					OnPropertyChanged("PeekType");
				}
			}
		}

		public double MeltGain
		{
			get
			{
				return _MeltGain;
			}
			set
			{
				if (_MeltGain != value)
				{
					_MeltGain = value;
					OnPropertyChanged("Gain");
				}
			}
		}

		public override void Copy(BasicOptionItem item)
		{
			base.Copy(item);
			MeltingOptionItem meltingOptionItem = item as MeltingOptionItem;
			MinTemperature = meltingOptionItem.MinTemperature;
			MaxTemperature = meltingOptionItem.MaxTemperature;
			NoiseThreshold = meltingOptionItem.NoiseThreshold;
			PeekWidthThreshold = meltingOptionItem.PeekWidthThreshold;
			PeekHightThreshold = meltingOptionItem.PeekHightThreshold;
			PeekType = meltingOptionItem.PeekType;
			MeltGain = meltingOptionItem.MeltGain;
		}

		public override void SetDefaultData()
		{
			base.SetDefaultData();
			MinTemperature = 60.0;
			MaxTemperature = 90.0;
			NoiseThreshold = 0.0;
			PeekWidthThreshold = 0.0;
			PeekHightThreshold = 10.0;
			PeekType = EPeekType.Positive;
		}

		protected override void GetData(List<PropertyKey> keys, List<byte[]> datas)
		{
			base.GetData(keys, datas);
			keys.Add(PropertyKey.Key_MinTemperature);
			datas.Add(BytesConverter.GetBytes(MinTemperature));
			keys.Add(PropertyKey.Key_MaxTemperature);
			datas.Add(BytesConverter.GetBytes(MaxTemperature));
			keys.Add(PropertyKey.Key_PeekHightThreshold);
			datas.Add(BytesConverter.GetBytes(PeekHightThreshold));
			keys.Add(PropertyKey.Key_PeekWidthThreshold);
			datas.Add(BytesConverter.GetBytes(PeekWidthThreshold));
			keys.Add(PropertyKey.Key_NoiseThreshold);
			datas.Add(BytesConverter.GetBytes(NoiseThreshold));
			keys.Add(PropertyKey.Key_PeekType);
			datas.Add(BytesConverter.GetBytes((int)PeekType));
			keys.Add(PropertyKey.Key_MeltGain);
			datas.Add(BytesConverter.GetBytes(MeltGain));
		}

		protected override void SetData(PropertyKey key, byte[] data)
		{
			base.SetData(key, data);
			switch (key)
			{
			case PropertyKey.Key_MinTemperature:
				MinTemperature = BytesConverter.BytesToDouble(data);
				break;
			case PropertyKey.Key_MaxTemperature:
				MaxTemperature = BytesConverter.BytesToDouble(data);
				break;
			case PropertyKey.Key_PeekHightThreshold:
				PeekHightThreshold = BytesConverter.BytesToDouble(data);
				break;
			case PropertyKey.Key_PeekWidthThreshold:
				PeekWidthThreshold = BytesConverter.BytesToDouble(data);
				break;
			case PropertyKey.Key_NoiseThreshold:
				NoiseThreshold = BytesConverter.BytesToDouble(data);
				break;
			case PropertyKey.Key_PeekType:
				PeekType = (EPeekType)BytesConverter.BytesToInt(data);
				break;
			case PropertyKey.Key_MeltGain:
				MeltGain = BytesConverter.BytesToDouble(data);
				break;
			}
		}

		public override void SaveToStream(StreamEx stream)
		{
			base.SaveToStream(stream);
		}

		public override bool ReadFromStream(StreamEx stream)
		{
			if (base.ReadFromStream(stream))
			{
				while (true)
				{
					switch (stream.ReadKey())
					{
					case PropertyKey.Key_MinTemperature:
						MinTemperature = stream.ReadDouble();
						break;
					case PropertyKey.Key_MaxTemperature:
						MaxTemperature = stream.ReadDouble();
						break;
					case PropertyKey.Key_PeekHightThreshold:
						PeekHightThreshold = stream.ReadDouble();
						break;
					case PropertyKey.Key_PeekWidthThreshold:
						PeekWidthThreshold = stream.ReadDouble();
						break;
					case PropertyKey.Key_NoiseThreshold:
						NoiseThreshold = stream.ReadDouble();
						break;
					default:
						stream.Seek(-4L, SeekOrigin.Current);
						return true;
					}
				}
			}
			return false;
		}
	}
}
